package com.tianpengtech.web.handler;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jfinal.handler.Handler;
import com.tianpengtech.im.common.utils.JsoupFilter;

public class XssHandler extends Handler {

	@Override
	public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
		

		if(target.indexOf(".") < 0){

			/***xss参数过滤***/
			Map<String, String[]> pmaps = request.getParameterMap();
			if(pmaps != null) {
				for(String key : pmaps.keySet()){
					int len = pmaps.get(key).length;
					String[] filters  = pmaps.get(key);
					for(int i=0; i<len ;i++){
						filters[i] = JsoupFilter.getBasic(pmaps.get(key)[i]);
					}
				}
			}
			/**xss url过滤**/
			target = JsoupFilter.getBasic(target);
		}
		
		next.handle(target, request, response, isHandled);
		
	}

}
